<?php

class Form_Register extends QForm
{
    function __construct($action)
    {
        // 调用父类的构造函数
        parent::__construct('form_register', $action);

        // 从配置文件载入表单
//		$filename = 'C:\apmxe\htdocs\jj_supermarket\_code\app\form\userlogin_form.yaml';
        $filename = dirname(__FILE__) . '/userregister_form.yaml';
        $this->loadFromConfig(Helper_YAML::loadCached($filename));
        $this->addValidations(user::meta());
        $this['password']->addValidations(User::meta(), 'password');
        $this['password2']->addValidations(User::meta(), 'password');
		$this['password2']->addValidations(User::meta(), 'password')
					  ->addValidations(array($this, 'checkPassword'), '两次输入的密码必须一致');
    }
	
	/**
     * 检查两次输入的新密码是否一致
     */
    function checkPassword($new_password)
    {
        return ($this['password2']->value == $this['password']->value);
    }
 
}
